package com.macro.mall.tiny.modules.pms.controller;


import com.macro.mall.tiny.common.api.CommonResult;
import com.macro.mall.tiny.modules.pms.model.PmsSkuStock;
import com.macro.mall.tiny.modules.pms.service.PmsSkuStockService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * sku的库存 前端控制器
 * </p>
 *
 * @author macro
 * @since 2024-08-15
 */
@RestController
@RequestMapping("/sku")
public class PmsSkuStockController {

    @Autowired
    private PmsSkuStockService skuStockService;

    @ApiOperation("获取sku信息")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public CommonResult<List<PmsSkuStock>> getItem(@PathVariable Long id,
                                                   @RequestParam(value = "keyword", required = false) String keyword) {
        List<PmsSkuStock> skuStockList = skuStockService.getSkuStockList(id, keyword);
        return CommonResult.success(skuStockList);
    }

    @ApiOperation("更新sku")
    @RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
    public CommonResult update(@RequestBody List<PmsSkuStock> skuStockList) {
        boolean result = skuStockService.update(skuStockList);
        return result ? CommonResult.success(result) : CommonResult.failed();
    }

}

